<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input
        v-model="query.carNumber"
        clearable
        placeholder="请输入内容"
        class="search-main"
      />
      <span class="search-label">状态：</span>
      <el-select v-model="query.paymentStatus">
        <el-option
          v-for="item in paymentStatusList"
          :key="item.id"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-button
        type="primary"
        class="search-btn"
        @click="serachFn"
        v-auth-dir="`parking:payment:list`"
      >查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="paymentList">
        <el-table-column type="index" label="序号" />
        <el-table-column label="车牌号码" prop="carNumber" />
        <el-table-column label="收费类型" prop="chargeType">
          <template #default="scope">
            {{ chargeType[scope.row.chargeType] }}
          </template>
        </el-table-column>
        <el-table-column label="停车总时长" prop="parkingTime" />
        <el-table-column label="缴纳费用（元）" prop="actualCharge" />
        <el-table-column label="缴纳状态" prop="paymentStatus">
          <template #default="scope">
            {{ status[scope.row.paymentStatus] }}
          </template>
        </el-table-column>
        <el-table-column label="缴纳方式" prop="paymentMethod">
          <template #default="scope">
            {{ methodType[scope.row.paymentMethod] }}
          </template>
        </el-table-column>
        <el-table-column label="缴纳时间" prop="paymentTime" />
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination
        layout="total, prev, pager, next,sizes"
        :page-size="query.pageSize"
        :page-sizes="[5,10,20,50]"
        :total="total"
        @current-change="handlePage"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script>
import { getPaymentListAPI } from '@/apis/payment'
export default {
  data() {
    return {
      query: {
        page: 1,
        pageSize: 5,
        carNumber: '',
        paymentStatus: ''
      },
      paymentList: [],
      total: 0,
      paymentStatusList: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '0',
          label: '未缴费'
        },
        {
          value: '1',
          label: '已缴费'
        }
      ],
      selectedCarList: [],
      type: '',
      methodType: {
        'Alipay': '支付宝',
        'WeChat': '微信',
        'Cash': '现金'
      }, // 支付方式
      status: {
        0: '未缴费',
        1: '已缴费'
      }, // 缴费状态
      chargeType: {
        temp: '临时停车',
        card: '月卡停车'
      }
    }
  },
  computed: {
    // total: ''
  },
  created() {
    this.getPaymentList()
  },
  methods: {
    // 修改当前页码
    handlePage(page) {
      this.query.page = page
      this.getPaymentList()
    },
    // 修改当前页信息条数
    handleSizeChange(pageSize) {
      this.query.pageSize = pageSize
      this.getPaymentList()
    },
    // 查询功能
    serachFn() {
      this.query.page = 1
      this.getPaymentList()
    },
    // 获取停车缴费列表
    async getPaymentList() {
      const res = await getPaymentListAPI(this.query)
      console.log(res)
      this.paymentList = res.data.rows
      this.total = res.data.total
    }
  }
}
</script>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.create-container {
  margin: 10px 0px;
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>
